
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<script language="JavaScript" type="text/javascript" src="../javascript/caltimer.js"></script>
<script language="JavaScript" type="text/javascript" src="../javascript/ajaxdeal.js"></script>

	<span style='width:0px;height:0px;position:absolute;top:0;left:0;filter:alpha(Opacity=50);background-color:white;display:none' id='showbuttomdiv' >
        <span style="width:0px;height:0px;" id="showbuttomdiv1"></span>
    </span>



    <div style="position:absolute;width:250px;height:120px;top:0;left:0;border-style:solid;border-width:1px;
         display:none;background-color:white;
         border-color:black;
         filter:shadow(color='red',direction=45)" id='showtopdiv' >

        <div style="width:250px;height:20px;background-image:url(../images/th_bgc.jpg);" align="right">
       
            <img src='../images/close_over.gif' style='border-width:0px;display:none;cursor:hand' onclick='hideHideFun()' id="closebutton" alt="关闭"/>
        </div>
        <table style='width:250px;height:60px' >
        <tr>
        	<td style='width:60px;height:40px;padding-top:7px' align='center'>
        	
        	<img src='../images/message_dialog.gif' style='border-width:0px;display:none;' id="warnimg"/>
        	<img src='../images/error_dialog.gif' style='border-width:0px;display:none;' id="errorimg" />
        		
        	</td>
        	
        	<td style='width:180px;height:40px;padding-top:7px'>
        	
        	 <div style='font-size:12px;color:black;width:180px;height:50px;overflow:hidden;padding-left:60px;padding-top:12px' id='dealshowmess' >数据处理中,请稍等....</div>
    		 <div>
        	</td>
        	
        </tr>
        </table> 
        <div style='width:100%' align='center'>
   			<img src='../images/loading.gif' style='border-width:0px' id="waitbar"/>
   			<input type='button' value='确  定' id='close_button' style='display:none;height:20px' onclick='hideHideFun()' />
   			<input type='button' value='确  定' id='delete_button' style='display:none;height:20px' onclick='realDFile()' />
   			<input type='button' value='取  消' id='cancel_button' style='display:none;height:20px' onclick='hideHideFun()' />
   		</div>
   
    </div>

<form action="registeraction.do" name="fileupload" enctype="MULTIPART/FORM-DATA" method ="post">

<input type="hidden" name="steptype" value="5"/>
<div id="regright">
  <table>
    <tr>
      <td class="textright"><img src="../images/botton_add.jpg" width="45" height="21" onclick = "addRow()"  style="cursor:hand" /></td>
    </tr>
  </table>
    
  <table cellspacing="0" class="regtable" >
    <tr class="thbgc">
      <th class="center" colspan='2' width="200px">文档名称</th>
      <th class="center" width="200px">上传时间</th>
      <th class ="center" width="200px">操作</th>
   </tr> 
     <logic:iterate id="att" name = "atts">
	     <tr >
	      <td class="center"  width="100px">${att.filename }</td>
	      <td class="center" width="100px"></td>
	      <td class="center" width="200px">${att.upload_date }</td>
	      <td id="${att.pk_da_att}" class ="center" width="200px"><img src="${pageContext.request.contextPath}/images/botton_delete.jpg" onclick="deleteAttFile('${att.pk_da_att}')" style='cursor:hand' width="60" height="20"/></td>
	   	</tr> 
     </logic:iterate>
     
  </table>
  
  <table cellspacing="0" class="regtable" id="fileuploadtable">
  </table>
  
  <table>
  <tr>
      <td colspan="5" class="f-12-F60000">说明：上传文档应为资质认证、供应产品信息等相关文档;<br />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;如果在添加上传文件时无法选择文件，请先设置浏览器到兼容型视图，具体请见首页相关操作手册。</td>
    </tr>
    <tr>
      <td colspan="5" class="center"><img style="cursor:hand" src="../images/up.jpg" width="60" height="20" onclick="up(4)"/>&nbsp;&nbsp;<img style="cursor:hand" src="../images/botton_submit.jpg" width="60" height="20" onclick="toMainIndex()" /></td>
    </tr>
  </table>
</div>
</form>

<input type="text" style="display:none" id="removefocuse"/>
<script language="javascript">

function up(index)
{
	window.location.href = "/portal/register/registeraction.do?uptype="+index;
}
var rowindex = 0;
//向批量上传文件的列表中添加一行数据
function addRow()
{
     var root = document.getElementById("fileuploadtable");
     

     var row = root.insertRow();
     

     row.style.height = '26px';
     
     
     
     rowindex++;
     row.id = "row"+rowindex;
     var cell1 = row.insertCell();
     
     cell1.align="center";
     
     cell1.width="100px";
    
     var cell2 = row.insertCell();
     
     cell2.align="center";

	 cell2.width="100px"
	 var innercontent = "  <input type='file' name='inputfile"+rowindex+"' id='file"+rowindex+"' style='position:absolute;opacity:0;filter:alpha(opacity=0); width:20px; height:20px' onchange='ondatachange(this,"+rowindex+")'  />  ";
     cell2.innerHTML = innercontent;
	  var cell3= row.insertCell();
     
    cell3.align = "center";
    var d = new Date();
   	cell3.innerText = d.getYear()+"-"+(parseInt(d.getMonth())+1)+"-"+d.getDate();
     
     cell3.width="200px";

     var cell4 = row.insertCell();
     
      cell4.width="200px";
     cell4.align="center";
     
     var img = "<img src='../images/botton_upload-.jpg' id='img"+rowindex+"' style='cursor:hand' border=0 style='cursor:hand'  onmouseover='showfiledialog("+rowindex+")'/>&nbsp<img src='../images/botton_delete.jpg' style='cursor:hand' border=0 style='cursor:hand' onclick='deleteRow("+rowindex+")'/>";
     cell4.innerHTML = img; 
}
function ondatachange(fileobject,index)
{
	if(fileobject.value != null && fileobject.value != "")
	{
		var fileType = fileobject.value.substring(fileobject.value.lastIndexOf(".")+1,fileobject.value.length);
		
		if(fileType == "zip" || fileType == "rar" || fileType == "7z"){
		 var row = document.getElementById("row"+index);
		 
		 var cells = row.cells;
		 var cell = cells[0];
		 cell.innerHTML =  fileobject.value.substring(fileobject.value.lastIndexOf("\\")+1,fileobject.value.lastIndexOf("."));
		 var img = document.getElementById("img"+index);
		 img.style.visibility = "hidden";
		 fileobject.style.display = "none";
		 }else{
		 
		 	alert("请上传压缩文件,文件大小不能超过30M");
		 }
		 
	}
}

//删除上传文件
function deleteRow(index)
{
	var root = document.getElementById("fileuploadtable");
	var row = "row"+index ;
	
	var rows = root.rows;
    var deletepos = 0;
    
    
    //寻找到对应的删除行并进行删除
	for(var pos = 0; pos < rows.length; pos++)
	{
		var temprow = rows[pos];
		if(temprow.id == row)
		{
			root.deleteRow(pos);
			deletepos = pos;
			rowindex--;
			break;
		}
	}
	
	
	/*
	//当删除行操作时更新显示索引
	for(var pos = deletepos; pos < rows.length; pos++)
	{
		var temprow = rows[pos];
		var cells = temprow.cells;
		
		var cell = cells[0];
		
		if(typeof(cell) == 'object')
		{
			cell.innerText = deletepos-1;
			deletepos++;
		}
	}	
	*/
}




function toMainIndex()
{
	document.fileupload.submit();
}
function showHideFun(){


    var showbuttomdiv = document.getElementById("showbuttomdiv");
    var showbuttomdiv1 = document.getElementById("showbuttomdiv1");

    var showtopdiv = document.getElementById("showtopdiv");
    var divHeight = document.body.scrollHeight;
	var divWidth = document.body.scrollWidth;
    var margintop = (divHeight-100)/2;
	var marginleft = (divWidth-200)/2;
    
    showbuttomdiv.style.height =divHeight;

    showbuttomdiv.style.width =divWidth;

    showbuttomdiv.style.display = "inline";
    showbuttomdiv1.style.height =divHeight;

    showbuttomdiv1.style.width =divWidth;

    showtopdiv.style.display = "inline";
    showtopdiv.style.top = margintop;
    showtopdiv.style.left = marginleft;

    document.getElementById("waitbar").style.display = "inline";
    
}

function hideHideFun(){
      var showbuttomdiv = document.getElementById("showbuttomdiv");
      var showtopdiv = document.getElementById("showtopdiv");
      showbuttomdiv.style.display = "none";
      showtopdiv.style.display = "none";
      var dealshowmess = document.getElementById("dealshowmess");
      dealshowmess.innerHTML = '数据处理中,请稍等....';
      document.getElementById("closebutton").style.display = "none";
      document.getElementById("warnimg").style.display = "none";
	  document.getElementById("errorimg").style.display = "none";
	  document.getElementById("close_button").style.display = 'none';
	  document.getElementById("dealshowmess").style.paddingLeft = '60px';

}


function changeShowMessage(message,end,warn,deleteObj,isRed,toFun){

     var dealshowmess = document.getElementById("dealshowmess");
      dealshowmess.innerHTML = message;
      if(end == 'yes'){

		document.getElementById("closebutton").style.display = "inline";
                    document.getElementById("waitbar").style.display = "none";
		}else if(end == 'error'){
		
			document.getElementById("warnimg").style.display = "none";
			document.getElementById("errorimg").style.display = "inline";
			document.getElementById("close_button").style.display = 'inline';
			document.getElementById("cancel_button").style.display = 'none';
			document.getElementById("delete_button").style.display = 'none';
		}
		
		if(warn == 'ok'){
			document.getElementById("warnimg").style.display = "inline";
			document.getElementById("errorimg").style.display = "none";
			document.getElementById("close_button").style.display = 'inline';
			document.getElementById("cancel_button").style.display = 'none';
			document.getElementById("delete_button").style.display = 'none';
			dealshowmess.style.paddingLeft = '20px';
			
		}else if(warn == 'error'){
			document.getElementById("warnimg").style.display = "none";
			document.getElementById("errorimg").style.display = "inline";
			document.getElementById("close_button").style.display = 'inline';
			document.getElementById("cancel_button").style.display = 'none';
			document.getElementById("delete_button").style.display = 'none';
			dealshowmess.style.paddingLeft = '20px';
		}else if(warn == 'delete'){
			document.getElementById("warnimg").style.display = "inline";
			document.getElementById("errorimg").style.display = "none";
			document.getElementById("close_button").style.display = 'none';
			document.getElementById("delete_button").style.display = 'inline';
			document.getElementById("cancel_button").style.display = 'inline';
			
			dealshowmess.style.paddingLeft = '20px';
		}else{
			document.getElementById("warnimg").style.display = "none";
			document.getElementById("errorimg").style.display = "none";
			document.getElementById("cancel_button").style.display = 'none';
			document.getElementById("delete_button").style.display = 'none';
		}
		
		
		if(typeof(deleteObj) == 'function'){
		
			deleteObj();
		}

		if(isRed){

			document.getElementById("close_button").onclick = function(){
				hideHideFun();
				toFun();
				
			};
		}
}

var deletefile  = new deleteFile();
function deleteFile(){
	this.att = null;
	this.dObject = null;
}



deleteFile.prototype.dFile = function(){


	showHideFun();
	changeShowMessage("开始删除附件信息!");
	try{
	var url = "";
	if(deletefile.att.indexOf('lyan') != -1){
		deletefile.att = deletefile.att.substring(0,deletefile.att.length-4);
		//如果含有lyan代表是供应商修改操作进行的附件删除，要先进行附件信息备份再进行删除
		url = "/portal/deletefile.do?type=record&attpk="+deletefile.att;
	}else{
		url = "/portal/deletefile.do?type=1&attpk="+deletefile.att;
	}
	ajax(url,returnFunction);
	}catch(e){
	
			changeShowMessage("处理附件出现问题!",'yes','error');	
	}
	

	//删除附件后返回信息
	function returnFunction(data){
	
	
		if(data == "ok"){
			changeShowMessage("附件删除成功!",'yes','ok');	
			
			
			
			var fileObj = deletefile.dObject;
			
			
			var parentNode = fileObj.parentNode;
			
			var parentNodeNode = parentNode.parentNode;
			parentNodeNode.removeChild(parentNode);
			
		}else{
			changeShowMessage("附件删除失败!",'error');	
		}
	}

}

function realDFile(){
		deletefile.dFile();
}
</script>
